Description:
Generally, when a class overrides the method
Object.Equals(),
it should also override
Object.GetHashCode()
and vice versa, a class overriding
Object.GetHashCode()
should also override
Object.Equals().
Otherwise, standard collection types,
such as hash tables, may not work correctly with instances of this class.
Incorrect:
public class Attribute {
object value;
public override bool Equals(object obj) {
return value.Equals(((Attribute) obj).value);
}
}
Correct:
public class Attribute {
object value;
public override bool Equals(object obj) {
return value.Equals(((Attribute) obj).value);
}
public override int GetHashCode() {
return value.GetHashCode();
}
}